<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：经费暂停-->
<div th:fragment="moneyinfoSuspended" class="modal inmodal fade" id="moneyinfoSuspended_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="moneyinfoSuspended_modalTitle">经费暂停</h4>
                <p id="moneyinfoSuspended_modalDesc" class="font-bold text-danger"></p>
            </div>
            <div class="modal-body">
                <form id="moneyinfoSuspended_Form">
                    <input id="moneyinfoSuspended_id" name="id" type="hidden"/>
                    <div class="row">
                        <div class="col-md-12">
                            <label for="moneyinfoSuspended_moneyTypeName">经费类型</label>
                            <input class="form-control" id="moneyinfoSuspended_moneyTypeName"
                                   name="moneyTypeName" disabled/>
                        </div>
                        <div class="col-md-12">
                            <label for="moneyinfoSuspended_projectName">预算项目</label>
                            <input class="form-control" id="moneyinfoSuspended_projectName"
                                   name="projectName" disabled/>
                        </div>
                        <div class="col-md-12">
                            <label for="moneyinfoSuspended_cateName">经济分类</label>
                            <input class="form-control typeahead" id="moneyinfoSuspended_cateName"
                                   name="cateName" disabled/>
                        </div>
                        <div class="col-md-12">
                            <label for="moneyinfoSuspended_totalMoney">暂停金额</label>
                            <input class="form-control" id="moneyinfoSuspended_totalMoney"
                                   name="totalMoney"/>
                        </div>
                        <div class="col-md-12">
                            <label for="moneyinfoSuspended_remark">备注</label>
                            <textarea class="form-control" id="moneyinfoSuspended_remark"
                                      name="remark"></textarea>
                        </div>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="moneyinfoSuspendedObj.saveHandler()">
                    保存
                </button>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            moneyinfoSuspendedObj.initForm();
        })
        var moneyinfoSuspendedObj = new Object({
            myForm: $('#moneyinfoSuspended_Form'),
            myModal: $('#moneyinfoSuspended_Modal'),
            myProject: undefined,
            myCate: undefined,
            dataRule: {
                money: {
                    required: true,
                    number: true,
                    min: 0.01,
                    toDecimal2: true
                },
                remark: {
                    maxlength: 400
                }
            },
            initForm() {
                let _self = this;
                this.myForm.validate({
                    rules: this.dataRule,
                    submitHandler: function (form) {
                        _self.save(form);
                    }
                });
            },
            init() {
                let _self = this;
                for (let key in moneyinfoObj.selectRow) {
                    if (_self.myForm.find(`input[name=${key}]`).length > 0) {
                        _self.myForm.find(`input[name=${key}]`).val(moneyinfoObj.selectRow[key])
                    }
                }
                _self.myForm.find((`input[name=totalMoney]`)).val(moneyinfoObj.selectRow.availableMoney);
                this.toggleModal(true)
            },
            toggleModal: function (show) {
                this.myModal.modal(show ? 'show' : 'hide');
            },
            save(form) {
                let _self = this;
                let formVals = $(form).serializeArray();
                let data = {}
                for (let i = 0; i < formVals.length; i++) {
                    data[formVals[i].name] = formVals[i].value;
                }
                let tipArr = [];
                tipArr.push(`费用类型：${moneyinfoObj.selectRow.moneyTypeName}`);
                tipArr.push(`预算项目：${moneyinfoObj.selectRow.projectName}`);
                tipArr.push(`经济分类：${moneyinfoObj.selectRow.cateName}`);
                tipArr.push(`暂停金额：${$.moneyFormat(data.totalMoney)}`);
                tipArr.push(`备注：${data.remark}`);
                $.mySwalConfirm(tipArr.join("\r\n"), function () {
                    $.myPost({
                        url: `/money/cur/moneyinfo/saveSuspended`,
                        dataType: 'json',
                        data: data,
                        success: function (data) {
                            if (data && data.code === 0) {
                                toastr.success(data.msg, '操作提示')
                                moneyinfoObj.refreshTable();
                                _self.myModal.modal('hide')
                            } else {
                                toastr.error(data.msg, '操作失败')
                            }
                        }
                    })
                }, "请再次确认信息", "my-sweet");
            },
            saveHandler() {
                this.myForm.submit();
            }
        })
    </script>

</div>
</body>
</html>